package yl.hs.bmipfull.daos.production;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import yl.hs.bmipfull.daos.BaseDao;
import yl.hs.bmipfull.pojo.production.ProductionRecordDetailsEntity;
import yl.hs.bmipfull.pojo.production.ProductionRecordEntity;
import yl.hs.bmipfull.viewmodels.base.StringDecimalModel;
import yl.hs.bmipfull.viewmodels.dataCockpit.ProductOutputModel;
import yl.hs.bmipfull.viewmodels.production.ProductionRecordModel;
import yl.hs.bmipfull.viewmodels.production.ProductionRecordSModel;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author 张凯
 * @apiNote 生产记录表持久层接口
 * @since 2021年10月25日 15时53分41秒
 */
@Repository
public interface IProductionRecordDao extends BaseDao<ProductionRecordEntity> {


    @Select("SELECT count(0) from production_record  WHERE productLineSn=#{productLineSn}")
    int getCountByLineSN(String productLineSn);
    /**
     * 分页查询生产记录表信息
     *
     * @param map           查询条件 {@link ProductionRecordEntity}
     * @param productCateSn 产品种类sn
     * @return 站内信息-List<{@link ProductionRecordEntity}>
     */
    List<ProductionRecordEntity> queryPage(@Param("map") Map<String, Object> map, String productCateSn);

    /**
     * 分页查询生产记录表信息
     *
     * @param map 查询条件 {@link ProductionRecordEntity}
     * @return 站内信息-List<{@link ProductionRecordEntity}>
     */
    List<String> queryListGroupByProductName(@Param("map") Map<String, Object> map);

    /**
     * 根据查询条件统计数据数量
     *
     * @param map 查询条件
     * @return 数据数量
     */
    Integer queryCountByCondition(@Param("map") Map<String, Object> map);


    /**
     * 获取当前生产线最大时间
     *
     * @param sn 生产线编号
     * @return 最大事件
     */


    Date selectMaxTime(String sn, @Param("type") String type);

    double queryProductionGroupDay(String productCate, String startTime, String endTime,List<String> lineSNList);

    @Select("SELECT COALESCE(SUM(actualOutput),0) from production_record  WHERE taskSn=#{taskSN}")
    double getSumNetWeightByTaskSn(String taskSN);

    @Select("SELECT COALESCE(SUM(actualOutput),0) from production_record  WHERE projectName=#{projectName} and projectPart=#{projectPart} and ProductName=#{productName}")
    double getSumNetWeightByProjectNameProjectPartProductName(String projectName, String projectPart, String productName);

    @Select("SELECT COUNT(0) from production_record  WHERE carGroup=1 and projectName=#{projectName} and projectPart=#{projectPart} and ProductName=#{productName}")
    Integer getTruckCountByTask(String projectName, String projectPart, String productName);

    /**
     * 根据日期、生产线编号、产品种类编号获取数量的汇总
     *
     * @param dateType 日期类型 1日 2周 3月
     * @param date     日期
     * @param lineSN   生产线编号
     * @return SumQuantity
     */
    BigDecimal getSumActualOutputByLineSNAndDate(int dateType, String date, String lineSN);

    BigDecimal getSumActualOutputByDate(int dateType, String date, String productCateSN);

    List<ProductionRecordDetailsEntity> queryDetailPage(@Param("map") Map<String, Object> query, String productCateSn);

    Long getRecordMaxId(String lineSN);

    Integer deleteRecordMax(@Param("id") Long id,@Param("lineSN") String lineSN);

    List<ProductionRecordEntity> queryLineDataByTime(@Param("lineSN") String lineSN, @Param("start") Date start, @Param("end") Date end);

    List<ProductionRecordDetailsEntity> queryLineDetailDataByTime(@Param("lineSN") String lineSN, @Param("start") Date start, @Param("end") Date end);

    List<ProductionRecordEntity> mortarProductionRecord(String startTime,String endTime);

    List<ProductionRecordModel> queryProductionRecordByHouse(Date startTime, Date endTime);
    List<ProductionRecordModel> queryProductionRecordByMonthon(Date startTime,Date endTime);

    double selectSumByCateSNAndDate(String productCateSN,Date date,int dateType);

    String  getActualProduction(String product, String timeType);

    String getPreviousCycleOfProductOutput(@Param("product")String product, @Param("timeType")String timeType);

    List<ProductOutputModel> getProportionEachProduct(String product, String timeType);

    List<ProductionRecordEntity> queryLinesDataByTime(@Param("lineSNList") List<String> lineSN, @Param("start") Date start, @Param("end") Date end);

    List<StringDecimalModel> queryLinesMonthOutputSummary(@Param("lineSNList") List<String> lineSN, @Param("start") Date start, @Param("end") Date end);

    List<ProductionRecordEntity> queryUnitProductionRecord(@Param("unit") String unit,@Param("start") Date day,@Param("end") Date endTime);
    List<ProductionRecordSModel> queryProductionRecordSModel(@Param("map") Map<String, Object> query);
    BigDecimal queryTotile(String rmsn,String unit);
}